package dkbta.ontology.elements.pattern.conditions;

import dkbta.ontology.elements.Element;

/**
 * A pair-wise condition on two pattern elements
 * 
 * @author Uri Kanonov
 */
public class PairWiseCondition{
	/** The ordinal of the first element in the pair */
	private final int _first;

	/** The ordinal of the second element in the pair */
	private final int _second;

	/** The temporal condition which is a part of the pair-wise condition */
	private final TemporalCondition _temporalCondition;

	/**
	 * Initializes a pair-wise condition
	 * 
	 * @param firstElementOrdinal The ordinal of the first element in the pair
	 * @param secondElementOrdinal The ordinal of the second element in the pair
	 * @param temporalCondition The temporal condition which is a part of the pair-wise
	 *        condition
	 */
	public PairWiseCondition(int firstElementOrdinal, int secondElementOrdinal,
		TemporalCondition temporalCondition){
		_first = firstElementOrdinal;
		_second = secondElementOrdinal;
		_temporalCondition = temporalCondition;
	}

	/**
	 * Returns the ordinal of the first element in this pairwise condition
	 * 
	 * @return The ordinal of the first element in this pairwise condition
	 */
	public int getFirst(){
		return _first;
	}

	/**
	 * Returns the ordinal of the second element in this pairwise condition
	 * 
	 * @return The ordinal of the second element in this pairwise condition
	 */
	public int getSecond(){
		return _second;
	}

	@Override
	public String toString(){
		StringBuilder sb = new StringBuilder();
		sb.append("\r\n\tFirst = #").append(_first).append(" Second = #").append(_second);
		sb.append("\r\n\t\tTemporal Condition: ").append(_temporalCondition);
		sb.append("\r\n");
		return sb.toString();
	}

	/**
	 * Checks whether the two given elements are matching the pair-wise condition
	 * 
	 * @param first The first element
	 * @param second The second element
	 * @return Whether the two given elements are matching the condition
	 */
	public boolean checkCondition(Element first, Element second){
		return _temporalCondition.checkCondition(first, second);
	}
}
